# 试验1：针对txt类型的文件进行内容读取
# 定义一个字典
dict = {}
# 打开文件
fileTxt = open('testdata.txt', 'r')
# 逐行读取文件内容
for line in fileTxt:
    print(line)

# 试验2：将字符串的内容进行拆分，并存入字典中
# 定义空字典
dictData = {}
data = '用例编号:testcase1,用户名:张三,密码:12345,预期结果:登录成功'
d = data.split(',')
print(d)
for i in d:
    r = i.split(':')
    # print(r)
    dictData[r[0]] = r[1]
print(dictData)

# 提取字典中的key
for key in dictData.keys():
    print(key)
# 提取字典中的value
for value in dictData.values():
    print(value)
for result in dictData.items():
    print(result)
# 提取字典指定内容，用例编号的值，预期结果的值
print(dictData['用例编号'])
print(dictData['预期结果'])

# 实际结果与预期结果进行比对
resultList = ['登陆成功']
if dictData['预期结果'] == resultList:
    r = '测试通过'
else:
    r = '测试失败'

# 写入文件
filereport = open('txtReport.txt', 'w')
filereport.write('执行测试用例' + dictData['用例编号'] + ':' + r)

# 试验3：字符串截取试验
strData = 'dsvjba;dvncadvc'
tmp1 = strData[1:-1:2]
print(tmp1)

tmp2 = strData.replace('a','-')
print(tmp2)